﻿namespace DueDatePickerSample.Controls
{
    using System;
    using Microsoft.Phone.Controls;

    public class DueDatePicker : DatePicker
    {
        public DueDatePicker()
        {
            this.Header = "DUE DATE";
            this.Value = null;
            this.PickerPageUri = new Uri("/Controls/DueDatePickerPage.xaml", UriKind.Relative);
        }

        protected override void OnValueChanged(DateTimeValueChangedEventArgs e)
        {
            // null values are changed inside control to default (Today) 
            // that's why we use here "yesterday" value for "no due date"
            if (this.Value == DateTime.Today.AddDays(-1))
            {
                this.Value = null;
            }

            base.OnValueChanged(e);
        }
    }
}
